﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PanelTween : MonoBehaviour
{
    public GameObject frameLineGameObject;
    public RectTransform actionListRect,baseViewRect,cameraViewRect,  animViewTween;

    public UGUITweenPosition FrameListTween,  subActionTween , baseViewPosTween,actionListPosTween;
    public UGUITweenValue actionListTween,baseViewRectTween,cameraViewTween,  animListViewTween;

    public bool IsFrameLineOpen()
    {
        return actionListRect.sizeDelta.y <= 500;
    }
    private void OnEnable()
    {
        baseViewRectTween.onUpdate = BaseViewRectTweenUpdate;
        actionListTween.onUpdate = ActionListTweenUpdate;
        cameraViewTween.onUpdate = CameraViewTweenUpdate;
        animListViewTween.onUpdate = AnimListViewTweenUpdate;
    }
    private void BaseViewRectTweenUpdate(UGUITweenValue tween, float value)
    {
        baseViewRect.sizeDelta = new Vector2(278, value);
    }
    private void AnimListViewTweenUpdate(UGUITweenValue tween, float value)
    {
        animViewTween.sizeDelta = new Vector2(animViewTween.sizeDelta.x, value);
    }
    private void ActionListTweenUpdate(UGUITweenValue tween, float value)
    {
        actionListRect.sizeDelta = new Vector2(actionListRect.sizeDelta.x, value);
    }
    private void CameraViewTweenUpdate(UGUITweenValue tween, float value)
    {
        cameraViewRect.sizeDelta = new Vector2(cameraViewRect.sizeDelta.x, value);
    }

    public void BaseViewActionSwitch(bool isOpenAction)
    {
        if (isOpenAction)
        {
            baseViewPosTween.PlayForward();
            actionListPosTween.PlayForward();
        }
        else
        {
            baseViewPosTween.PlayReverse();
            actionListPosTween.PlayReverse();
        }
    }

    public void OpenSubActionList(bool isOpen)
    {
        if (isOpen)
        {
            //由于事件注册在OnEnable 这里即使先active true 也不一定会能先注册
            subActionTween.gameObject.SetActive(true);
            subActionTween.onFinished = null;
            subActionTween.PlayForward();

            animListViewTween.PlayForward();
        }
        else
        {
            subActionTween.AddOnFinished(SubActionTweenFinished);
            subActionTween.PlayReverse();

            animListViewTween.PlayReverse();
        }
    }
    private void SubActionTweenFinished()
    {
        subActionTween.gameObject.SetActive(true);
    }

    public void OpenFrameLineTween(bool isOpen)
    {
        if (!isOpen)
        {
            frameLineGameObject.SetActive(true);
            FrameListTween.onFinished = null;
            FrameListTween.PlayForward();

            baseViewRectTween.PlayForward();
            actionListTween.PlayForward();
            cameraViewTween.PlayForward();
        }
        else
        {
            UGUIEventDelegate.Add( FrameListTween.onFinished, FrameListTweenFinished );
            FrameListTween.PlayReverse();

            baseViewRectTween.PlayReverse();
            actionListTween.PlayReverse();
            cameraViewTween.PlayReverse();
        }
    }
    private void FrameListTweenFinished()
    {
        frameLineGameObject.SetActive(false);
    }
}
